package com.breeze.blockchain.controller.admin;

import com.breeze.blockchain.mybatis.entity.SettingDo;
import com.breeze.blockchain.service.SettingService;
import com.breeze.components.web.core.ResponseDTO;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import java.util.Optional;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * 后台公开接口
 *
 * @author breeze
 * @since 2024-05-11 23:21:51
 */
@RestController
@Tag(name = "后台公开接口")
@RequestMapping("api/admin/public")
public class AdminPublicController {

  @Resource private SettingService settingService;

  @Operation(summary = "配置获取")
  @GetMapping("setting/get")
  public ResponseDTO<String> getSetting(@RequestParam String key) {
    return ResponseDTO.ok(
        Optional.ofNullable(settingService.getKeyByValue(key))
            .map(SettingDo::getValue)
            .orElse(null));
  }
}
